package cn.edu.sdyu.ie.crs.repository;

import cn.edu.sdyu.ie.crs.common.response.LabelValue;
import cn.edu.sdyu.ie.crs.domain.Classroom;
import cn.edu.sdyu.ie.crs.domain.Device;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DeviceRepository extends JpaRepository<Device, Integer> {

    Device findByDeviceCode(String deviceCode);

    @Query(value = "SELECT d.device_type AS label, count(*) AS value"
            + " FROM device d"
            + " WHERE d.device_type IS NOT NULL"
            + " GROUP BY d.device_type", nativeQuery = true)
    List<LabelValue> countGroupByDeviceType();

    List<Device> findDevicesByClassroomId(Integer classroomId);
}
